package com.lysj.food.food.repository;

import com.lysj.admin.utils.spring.foundation.base.BaseRepository;
import com.lysj.food.food.domain.Food;
import com.lysj.food.food.vo.BackGroundFoodVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Created by wtl on 2019-03-19 16:00:45
 * @description 菜品dao
 */
public interface FoodRepository extends BaseRepository<Food> {

    /**
     * 通过菜品类型id查询菜品id列表
     *
     * @param foodTypeId 菜品类型id
     */
    List<Food> findByFoodTypeId(String foodTypeId);

    /**
     * 获取本门店还未设置为默认下单的菜品，本门店的菜品列表去除已经在默认下单表中的菜品
     */
    @Query("from Food f where f.storeId=?1 and f.id not in(select foodId from DefaultFood)")
    Page<Food> findNotDefaultFood(String storeId, Pageable pageable);


    /**
     * 获取本门店所有菜品(类型名称,菜品id,菜品名称，销售价),后台列表使用
     */
    @Query(value = "SELECT NEW com.lysj.food.food.vo.BackGroundFoodVo(b.name,a.id,a.name,a.onSale,a.photoId) FROM Food a ,FoodType b  WHERE a.storeId=?1 AND a.delFlag=1 AND a.foodTypeId=b.id  ORDER BY a.createTime DESC ")
    Page<BackGroundFoodVo> findStoreFoodList(Pageable pageable, String storeId);

    /**
     * 获取菜品类型对应的菜品，小程序用
     */
    @Query(value = "SELECT NEW com.lysj.food.food.vo.BackGroundFoodVo(b.name,a.id,a.name,a.onSale,a.photoId) FROM Food a ,FoodType b  WHERE a.foodTypeId = b.id and a.delFlag=1 AND a.foodTypeId=?1  ORDER BY a.createTime DESC ")
    List<BackGroundFoodVo> findFoodListByFoodTypeId(String foodTypeId);


    /**
     * 获取打印区域关联的菜品列表
     */
    List<Food> findByAreaId(String areaId);


}